package com.goodving.guli.bt.profile.scale;

import android.annotation.SuppressLint;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGattCharacteristic;
import android.content.Context;
import android.util.Pair;

import com.goodving.guli.bt.C1041c;
import com.goodving.guli.bt.C1725b;
import com.goodving.guli.bt.C3859a;
import com.goodving.guli.bt.model.C1060e;
import com.goodving.guli.bt.model.C3908f;
import com.goodving.guli.bt.model.C3910h;
import com.goodving.guli.bt.model.C3911i;
import com.goodving.guli.bt.model.C3912j;
import com.goodving.guli.bt.model.C3918p;
import com.goodving.guli.bt.model.C3919q;
import com.goodving.guli.bt.model.C3921s;
import com.goodving.guli.bt.model.UserInfo;
import com.goodving.guli.view.C4220a;

import java.util.Calendar;
import java.util.GregorianCalendar;

/**
 * Created by john on 2015/11/25.
 */
public class C3942j extends GattPeripheral {
    private static final byte aA = (byte) 8;
    private static final byte aB = (byte) 9;
    private static final byte aC = (byte) 10;
    private static final byte aD = (byte) 11;
    private static final byte aE = (byte) 12;
    private static final byte aF = (byte) 14;
    private static final byte aG = (byte) 15;
    private static final byte aH = (byte) 20;
    private static final byte aI = (byte) 17;
    private static final byte aJ = (byte) 18;
    private static final byte aK = (byte) 19;
    private static final byte aL = (byte) 1;
    private static final byte aM = (byte) 2;
    private static final byte aN = (byte) 3;
    private static final byte aO = (byte) 5;
    public static final String af = "2.0.0.20140514";
    public static final String ag;
    public static final String ah;
    public static final String ai;
    public static final String aj;
    public static final String ak;
    public static final String al;
    public static final byte am = (byte) 0;
    public static final byte an = (byte) 1;
    public static final byte ao = (byte) 2;
    public static final byte ap = (byte) 20;
    public static final byte aq = (byte) 21;
    private static final String ar = "MiLiProfile";
    private static final String as;
    private static final String at;
    private static final String au;
    private static final byte av = (byte) 3;
    private static final byte aw = (byte) 4;
    private static final byte ax = (byte) 5;
    private static final byte ay = (byte) 6;
    private static final byte az = (byte) 7;
    private BluetoothGattCharacteristic aP;
    private BluetoothGattCharacteristic aQ;
    private BluetoothGattCharacteristic aR;
    private BluetoothGattCharacteristic aS;
    private BluetoothGattCharacteristic aT;
    private BluetoothGattCharacteristic aU;
    private BluetoothGattCharacteristic aV;
    private BluetoothGattCharacteristic aW;
    private BluetoothGattCharacteristic aX;
    private BluetoothGattCharacteristic aY;
    private BluetoothGattCharacteristic aZ;
    private BluetoothGattCharacteristic ba;
    private BluetoothGattCharacteristic bb;
    private BluetoothGattCharacteristic bc;
    private BluetoothGattCharacteristic bd;
    private BluetoothGattCharacteristic be;
    private BluetoothGattCharacteristic bf;
    private BluetoothGattCharacteristic bg;
    private BluetoothGattCharacteristic bh;
    private BluetoothGattCharacteristic bi;
    private BluetoothGattCharacteristic bj;
    private BluetoothGattCharacteristic bk;
    private C3910h bl;
    private C3908f bm;
    private XMBleMessageHandler bn;
    private C1041c bo;
    private int bp;
    private C1060e bq;
    private boolean br;
    private Integer bs;
    private Integer bt;
    private Integer bu;

    static {
        GuliLog.INFO(C3942j.class.getSimpleName() + ".VERSION: " + af);
        as = C3942j.class.getPackage().getName();
        at = C3942j.class.getSimpleName();
        au = as + "." + at;
        ag = au + ".INTENT_ACTION_INITIALIZATION_SUCCESS";
        ah = au + ".INTENT_ACTION_INITIALIZATION_FAILED";
        ai = au + ".INTENT_ACTION_AUTHENTICATION_SUCCESS";
        aj = au + ".INTENT_ACTION_AUTHENTICATION_FAILED";
        ak = au + ".INTENT_ACTION_DEVICE_STATUS_CHANGED";
        al = au + ".INTENT_ACTION_DEVICE_BATTERY_STATUS_CHANGED";
    }

    public C3942j(Context context, BluetoothDevice bluetoothDevice, C1724A c1724a) {
        super(context, bluetoothDevice, c1724a);
        this.aP = null;
        this.aQ = null;
        this.aR = null;
        this.aS = null;
        this.aT = null;
        this.aU = null;
        this.aV = null;
        this.aW = null;
        this.aX = null;
        this.aY = null;
        this.aZ = null;
        this.ba = null;
        this.bb = null;
        this.bc = null;
        this.bd = null;
        this.be = null;
        this.bf = null;
        this.bg = null;
        this.bh = null;
        this.bi = null;
        this.bj = null;
        this.bk = null;
        this.bl = null;
        this.bm = null;
        this.bn = null;
        this.bo = null;
        this.bp = -1;
        this.bq = null;
        this.br = false;
        this.bs = Integer.valueOf(-1);
        this.bt = Integer.valueOf(-1);
        this.bu = Integer.valueOf(-1);
        GuliLog.m12371e();
    }

    private static void m25553X() {
    }

    private static void m25554Y() {
    }

    private boolean m25560e(int i) {
        switch (i) {
            case 1 /*1*/:
            case C4220a.f20888k /*2*/:
            case C4220a.aW /*11*/:
            case C4220a.be /*12*/:
                this.bs = Integer.valueOf(i);
                m25292a((Object) this.aW);
                return true;
            case C4220a.f20875X /*5*/:
            case C4220a.bt /*6*/:
            case C4220a.bo /*9*/:
            case C4220a.bd /*10*/:
                this.bt = Integer.valueOf(i);
                m25292a((Object) this.aS);
                return true;
            case C4220a.ba /*8*/:
                this.bu = Integer.valueOf(i);
                m25292a((Object) this.aX);
                return true;
            default:
                return false;
        }
    }

    public C3911i m25561A() {
        byte[] g;
        C3911i c3911i = new C3911i();
        if (this.bg != null) {
            Object g2 = read(this.bg);
//            if (g2 != null && g2.length >= 6) {
//                Object obj = new byte[6];
//                System.arraycopy(g2, 0, obj, 0, 6);
//                c3911i.f19720c = new String(obj);
//            }
        }
        if (this.bi != null) {
            g = read(this.bi);
            if (g != null && g.length == 8) {
                c3911i.f19718a = String.format("%02X%02X%02X%02X%02X%02X%02X%02X", new Object[]{Byte.valueOf(g[0]), Byte.valueOf(g[1]), Byte.valueOf(g[2]), Byte.valueOf(g[3]), Byte.valueOf(g[4]), Byte.valueOf(g[5]), Byte.valueOf(g[6]), Byte.valueOf(g[7])});
            }
        }
        if (this.bh != null) {
            g = read(this.bh);
            if (g != null && g.length > 0) {
                c3911i.f19719b = new String(g);
            }
        }
        if (this.bj != null) {
            g = read(this.bj);
            if (g != null && g.length == 7) {
                GuliLog.tracePrintInfo(ar, "pnp id:" + GattUtils.m25335b(g));
                C3919q c3919q = new C3919q();
                c3919q.f19738d = g[0] & HeartRateInfo.HR_EMPTY_VALUE;
                c3919q.f19735a = ((g[2] & HeartRateInfo.HR_EMPTY_VALUE) << 8) | (g[1] & HeartRateInfo.HR_EMPTY_VALUE);
                c3919q.f19736b = ((g[4] & HeartRateInfo.HR_EMPTY_VALUE) << 8) | (g[3] & HeartRateInfo.HR_EMPTY_VALUE);
                c3919q.f19737c = (g[5] & HeartRateInfo.HR_EMPTY_VALUE) | ((g[6] & HeartRateInfo.HR_EMPTY_VALUE) << 8);
                c3911i.f19721d = c3919q;
            }
        }
        GuliLog.m12370d(ar, "general device info:" + c3911i);
        return c3911i;
    }

    public C3910h m25562B() {
        GuliLog.m12371e();
        return this.bl;
    }

    public void m25563C() {
        this.bt = Integer.valueOf(C3934a.ac);
        if (this.aS != null) {
            m25292a((Object) this.aS);
        }
    }

    public boolean m25564D() {
        GuliLog.m12371e();
        return write(this.aT, new byte[]{aI});
    }

    public boolean m25565E() {
        GuliLog.m12371e();
        return write(this.aT, new byte[]{aD});
    }

    public boolean m25566F() {
        GuliLog.m12371e();
        if (this.bd == null) {
            return false;
        }
        return write(this.bd, new byte[]{ao});
    }

    public UserInfo m25567G() {
        int i = 0;
        GuliLog.m12371e();
        byte[] g = read(this.aS);
        GuliLog.ASSERT_NOT_NULL((Object) g);
        if (g == null || g.length == 0) {
            return null;
        }
        int i2;
        GuliLog.ASSERTION_TRUE(g.length == 20);
        byte[] bArr = new byte[19];
        for (i2 = 0; i2 < 19; i2++) {
            bArr[i2] = g[i2];
        }
        i2 = GattUtils.m25342d(bArr);
        String address = m25277f().getAddress();
        if (g[19] != ((byte) (i2 ^ Integer.decode("0x" + address.substring(address.length() - 2)).intValue()))) {
            return null;
        }
        int a = GattUtils.m25320a(g, 0);
        byte b = g[4];
        byte b2 = g[5];
        byte b3 = g[6];
        byte b4 = g[7];
        byte[] bArr2 = new byte[11];
        while (i < bArr2.length) {
            bArr2[i] = g[i + 8];
            i++;
        }
        return new UserInfo(a, b, b2, b3, b4, bArr2);
    }

    public String m25568H() {
        GuliLog.m12371e();
        byte[] g = read(this.aQ);
        return g == null ? null : new String(g);
    }

    public Pair<Calendar, Calendar> m25569I() {
        GuliLog.m12371e();
        byte[] g = read(this.aY);
        if (g == null || g.length == 0) {
            return null;
        }
        GuliLog.ASSERTION_TRUE(g.length == 12);
        Calendar gregorianCalendar = new GregorianCalendar();
        Calendar gregorianCalendar2 = new GregorianCalendar();
        gregorianCalendar.set(Calendar.YEAR, g[0] + C4220a.bZ);
        gregorianCalendar.set(Calendar.MONTH, g[1]);
        gregorianCalendar.set(Calendar.DATE, g[2]);
        gregorianCalendar.set(Calendar.HOUR_OF_DAY, g[3]);
        gregorianCalendar.set(Calendar.MINUTE, g[4]);
        gregorianCalendar.set(Calendar.SECOND, g[5]);
        gregorianCalendar2.set(Calendar.YEAR, g[6] + C4220a.bZ);
        gregorianCalendar2.set(Calendar.MONTH, g[7]);
        gregorianCalendar2.set(Calendar.DATE, g[8]);
        gregorianCalendar2.set(Calendar.HOUR_OF_DAY, g[9]);
        gregorianCalendar2.set(Calendar.MINUTE, g[10]);
        gregorianCalendar2.set(Calendar.SECOND, g[11]);
        return new Pair(gregorianCalendar, gregorianCalendar2);
    }

    public C3921s m25570J() {
        GuliLog.m12371e();
        if (this.aZ == null) {
            return null;
        }
        byte[] g = read(this.aZ);
        if (g == null) {
            return null;
        }
        GuliLog.ASSERTION_TRUE(g.length == 20);
        return new C3921s((int) (((double) GattUtils.m25320a(g, 0)) / 1.6d), GattUtils.m25320a(g, 4), GattUtils.m25320a(g, 8), GattUtils.m25320a(g, 12), GattUtils.m25320a(g, 16));
    }

    public boolean m25571K() {
        GuliLog.m12371e();
        return true;
    }

    public C3908f m25572L() {
        GuliLog.m12371e();
        byte[] g = read(this.ba);
        if (g == null || g.length == 0) {
            return null;
        }
        GuliLog.ASSERTION_TRUE(g.length == 10);
        byte b = g[0];
        Calendar gregorianCalendar = new GregorianCalendar();
        gregorianCalendar.set(Calendar.YEAR, g[1] + C4220a.bZ);
        gregorianCalendar.set(Calendar.MONTH, g[2]);
        gregorianCalendar.set(Calendar.DATE, g[3]);
        gregorianCalendar.set(Calendar.HOUR_OF_DAY, g[4]);
        gregorianCalendar.set(Calendar.MINUTE, g[5]);
        gregorianCalendar.set(Calendar.SECOND, g[6]);
        this.bm = new C3908f(b, gregorianCalendar, ((g[7] & HeartRateInfo.HR_EMPTY_VALUE) | ((g[8] & HeartRateInfo.HR_EMPTY_VALUE) << 8)) & 65535, g[9]);
        return this.bm;
    }

    public boolean m25573M() {
        GuliLog.m12371e();
        return true;
    }

    public C3908f m25574N() {
        return this.bm;
    }

    public int m25575O() {
        byte[] g = read(this.bb);
        if (g == null || g.length != 4) {
            return -1;
        }
        return ((g[3] & HeartRateInfo.HR_EMPTY_VALUE) << 24) | (((g[0] & HeartRateInfo.HR_EMPTY_VALUE) | ((g[1] & HeartRateInfo.HR_EMPTY_VALUE) << 8)) | ((g[2] & HeartRateInfo.HR_EMPTY_VALUE) << 16));
    }

    @Deprecated
    public boolean m25576P() {
        GuliLog.m12371e();
        return write(this.aT, new byte[]{aK});
    }

    public boolean m25577Q() {
        GuliLog.m12371e();
        return write(this.aT, new byte[]{aB});
    }

    public boolean m25578R() {
        GuliLog.m12371e();
        return write(this.aT, new byte[]{aE});
    }

    public boolean m25579S() {
        GuliLog.m12371e();
        return write(this.bb, new byte[]{an});
    }

    public boolean m25580T() {
        GuliLog.m12371e();
        return write(this.bb, new byte[]{ao});
    }

    public boolean m25581U() {
        return write(this.aT, new byte[]{ay});
    }

    public void m25582V() {
        m25268b(this.aV);
    }

    public C3912j m25583W() {
        boolean z = false;
        GuliLog.m12371e();
        if (this.bf == null) {
            return null;
        }
        byte[] g = read(this.bf);
        if (g == null || g.length < 2) {
            return null;
        }
        if ((g[0] & HeartRateInfo.HR_EMPTY_VALUE) == 1) {
            z = true;
        }
        return new C3912j(z, g[1] & HeartRateInfo.HR_EMPTY_VALUE);
    }

    public void m25584a(INotifyCallback c3838b) {
        m25265a(this.aV, c3838b);
    }

    public void m25585a(C1041c c1041c) {
        this.bo = c1041c;
    }

    public void m25586a(XMBleMessageHandler XMBleMessageHandler) {
        this.bn = XMBleMessageHandler;
    }

    @Deprecated
    public boolean m25587a(byte b) {
        GuliLog.m12371e();
        return write(this.aT, new byte[]{aA, b});
    }

    public boolean m25588a(byte b, byte b2) {
        GuliLog.m12371e();
        if (this.bf == null) {
            return false;
        }
        return write(this.bf, new byte[]{aq, b, b2});
    }

    public boolean m25589a(byte b, byte b2, byte b3, byte b4) {
        return write(this.aT, new byte[]{aF, b, b2, b3, b4});
    }

    public boolean m25542a(byte b, byte b2, Calendar calendar, byte b3, byte b4) {
        GuliLog.m12371e();
        byte b5 = (byte) (calendar.get(Calendar.YEAR) - 2000);
        byte b6 = (byte) calendar.get(Calendar.MONTH);
        byte b7 = (byte) calendar.get(Calendar.DATE);
        byte b8 = (byte) calendar.get(Calendar.HOUR_OF_DAY);
        byte b9 = (byte) calendar.get(Calendar.MINUTE);
        byte b10 = (byte) calendar.get(Calendar.SECOND);
        return write(this.aT, new byte[]{aw, b, b2, b5, b6, b7, b8, b9, b10, b3, b4});
    }

    public boolean m25591a(byte b, int i) {
        GuliLog.m12371e();
        return write(this.aT, new byte[]{ax, b, (byte) (i & HeartRateInfo.HR_EMPTY_VALUE), (byte) ((i >> 8) & HeartRateInfo.HR_EMPTY_VALUE)});
    }

    public boolean m25592a(int i, int i2, int i3, int i4) {
        boolean z = true;
        GuliLog.m12371e();
        this.bs = Integer.valueOf(-1);
        if (!write(this.aT, new byte[]{az, (byte) i, (byte) (i >> 8), (byte) (i >> 16), (byte) (i >> 24), (byte) i2, (byte) (i2 >> 8), (byte) (i2 >> 16), (byte) (i2 >> 24), (byte) i3, (byte) (i3 >> 8), (byte) i4, (byte) (i4 >> 8)})) {
            return false;
        }
//        if (this.bs.intValue() == -1) {
//            m25293a(this.aT, C3075a.f16147a);
//        }
//        if (this.bs.intValue() != 12) {
//            z = false;
//        }
        return z;
    }


    public boolean m25593a(int i, int i2, int i3, int i4, int i5) {
        boolean z = true;
        GuliLog.m12371e();
        this.bu = Integer.valueOf(-1);
        if (!write(this.aX, new byte[]{(byte) (i & HeartRateInfo.HR_EMPTY_VALUE), (byte) ((i >> 8) & HeartRateInfo.HR_EMPTY_VALUE), (byte) (i2 & HeartRateInfo.HR_EMPTY_VALUE), (byte) ((i2 >> 8) & HeartRateInfo.HR_EMPTY_VALUE), (byte) (i3 & HeartRateInfo.HR_EMPTY_VALUE), (byte) ((i3 >> 8) & HeartRateInfo.HR_EMPTY_VALUE), (byte) (i4 & HeartRateInfo.HR_EMPTY_VALUE), (byte) ((i4 >> 8) & HeartRateInfo.HR_EMPTY_VALUE), am, am, (byte) (i5 & HeartRateInfo.HR_EMPTY_VALUE), (byte) ((i5 >> 8) & HeartRateInfo.HR_EMPTY_VALUE)})) {
            return false;
        }
        if (this.bu.intValue() == -1) {
            m25293a(this.aX, C4220a.bS);
        }
        if (this.bu.intValue() != 8) {
            z = false;
        }
        return z;
    }

    public boolean m25544a(UserInfo userInfo) {
        GuliLog.m12371e();
        boolean b = m25546b(userInfo);
        GuliLog.ASSERTION_TRUE(b);
        if (!b) {
            return false;
        }
        b = m25597a(Calendar.getInstance());
        GuliLog.ASSERTION_TRUE(b);
        return b;
    }

    public boolean m25595a(UserInfo userInfo, C3859a c3859a) {
        this.bt = Integer.valueOf(-1);
        if (m25546b(userInfo)) {
            if (this.bt.intValue() == -1) {
                m25293a(this.aS, 10000);//TBD
            }
            if (this.bt.intValue() == -1) {
                c3859a.m25191f();
                return false;
            } else if (this.bt.intValue() == 6) {
                c3859a.m25188c();
                this.bt = Integer.valueOf(-1);
                m25293a(this.aS, C4220a.as);
                if (this.bt.intValue() == -1) {
                    c3859a.m25191f();
                    return false;
                } else if (this.bt.intValue() == 9) {
                    c3859a.m25189d();
                    return false;
                } else if (this.bt.intValue() == 10) {
                    c3859a.m25190e();
                    return true;
                } else {
                    c3859a.m25192g();
                    return false;
                }
            } else if (this.bt.intValue() == 5) {
                c3859a.m25187b();
                return true;
            } else {
                c3859a.m25192g();
                return false;
            }
        }
        c3859a.m25186a();
        return false;
    }

    public boolean m25596a(String str) {
        GuliLog.m12371e();
        return write(this.aQ, str.getBytes());
    }

    public boolean m25597a(Calendar calendar) {
        GuliLog.m12371e();
        byte b = (byte) (calendar.get(Calendar.YEAR) - 2000);
        byte b2 = (byte) calendar.get(Calendar.MONTH);
        byte b3 = (byte) calendar.get(Calendar.DATE);
        byte b4 = (byte) calendar.get(Calendar.HOUR_OF_DAY);
        byte b5 = (byte) calendar.get(Calendar.MINUTE);
        byte b6 = (byte) calendar.get(Calendar.SECOND);
        return write(this.aY, new byte[]{b, b2, b3, b4, b5, b6, (byte) -1, (byte) -1, (byte) -1, (byte) -1, (byte) -1, (byte) -1});
    }

    public boolean m25598a(Calendar calendar, int i) {
        GuliLog.m12371e();
        byte b = (byte) (calendar.get(Calendar.YEAR) - 2000);
        byte b2 = (byte) calendar.get(Calendar.MONTH);
        byte b3 = (byte) calendar.get(Calendar.DATE);
        byte b4 = (byte) calendar.get(Calendar.HOUR_OF_DAY);
        byte b5 = (byte) calendar.get(Calendar.MINUTE);
        byte b6 = (byte) calendar.get(Calendar.SECOND);
        return write(this.aT, new byte[]{aC, b, b2, b3, b4, b5, b6, (byte) (i & HeartRateInfo.HR_EMPTY_VALUE), (byte) ((i >> 8) & HeartRateInfo.HR_EMPTY_VALUE)});
    }

    public boolean m25545a(boolean z, C1060e c1060e) {
        GuliLog.m12371e();
        this.bq = c1060e;
        return true;
    }

    public boolean m25600a(byte[] bArr) {
        int i = 0;
        GuliLog.ASSERTION_TRUE(bArr.length == 16);
        byte[] bArr2 = new byte[17];
        bArr2[0] = aw;
        while (i < 16) {
            bArr2[i + 1] = bArr[i];
            i++;
        }
        return write(this.bb, bArr2);
    }

    public boolean m25601a(byte[] bArr, C1725b c1725b) {
        int i;
        boolean b;
        GuliLog.m12371e();
        int length = bArr.length;
        int i2 = length / 20;
        GuliLog.m12350a("totalPackets = " + i2);
        if (c1725b != null) {
            c1725b.setMax(length);
        }
        this.bs = Integer.valueOf(-1);
        int i3 = 0;
        int i4 = 0;
        int i5 = 0;
        while (i3 < i2) {
            byte[] bArr2 = new byte[20];
            for (i = 0; i < 20; i++) {
                bArr2[i] = bArr[(i3 * 20) + i];
            }
            b = write(this.aW, bArr2);
            GuliLog.ASSERTION_TRUE(b);
            if (!b) {
                return false;
            }
            i4 += 20;
            if (c1725b != null) {
                c1725b.report(i4);
            }
            i = i5 + 20;
            GuliLog.m12350a("transferedPackets = " + i);
            if (i >= C3515h.f17660E) {
                m25565E();
                i = 0;
            }
            i3++;
            i5 = i;
        }
        if (length % 20 == 0) {
            m25565E();
            GuliLog.m12350a("transferFirmwareData: complete");
            return true;
        }
        byte[] bArr3 = new byte[(length % 20)];
        for (i = 0; i < length % 20; i++) {
            bArr3[i] = bArr[(i2 * 20) + i];
        }
        b = write(this.aW, bArr3);
        GuliLog.ASSERTION_TRUE(b);
        if (!b) {
            return false;
        }
        i = (length % 20) + i4;
        if (c1725b != null) {
            c1725b.report(i);
        }
        GuliLog.m12350a("transferedPackets = " + ((length % 20) + i5));
        m25565E();
        GuliLog.m12350a("transferFirmwareData: complete");
        if (this.bs.intValue() == -1) {
            m25293a(this.aW, 20000);
        }
        return this.bs.intValue() == 2;
    }

    public void m25602b(int i) {
        this.d_ = i;
    }

    public void m25603b(boolean z) {
        m25294a(z);
        m25267b();
    }

    public boolean m25604b(byte b) {
        if (this.bk == null) {
            return false;
        }
        return write(this.bk, new byte[]{b});
    }

    public boolean m25605b(int i, int i2, int i3, int i4, int i5) {
        boolean z = true;
        GuliLog.m12371e();
        this.bs = Integer.valueOf(-1);
        if (!write(this.aT, new byte[]{az, (byte) i, (byte) (i >> 8), (byte) (i >> 16), (byte) (i >> 24), (byte) i2, (byte) (i2 >> 8), (byte) (i2 >> 16), (byte) (i2 >> 24), (byte) i3, (byte) (i3 >> 8), (byte) i4, (byte) (i4 >> 8), (byte) i5})) {
            return false;
        }
        if (this.bs.intValue() == -1) {
            m25293a(this.aW, 5000);
        }
        if (this.bs.intValue() != 12) {
            z = false;
        }
        return z;
    }

    public boolean m25546b(UserInfo userInfo) {
        int i = 9;
        int i2 = 0;
        GuliLog.m12371e();
        byte[] bArr = new byte[20];
        bArr[0] = (byte) (userInfo.f19670d & HeartRateInfo.HR_EMPTY_VALUE);
        bArr[1] = (byte) ((userInfo.f19670d >> 8) & HeartRateInfo.HR_EMPTY_VALUE);
        bArr[2] = (byte) ((userInfo.f19670d >> 16) & HeartRateInfo.HR_EMPTY_VALUE);
        bArr[3] = (byte) ((userInfo.f19670d >> 24) & HeartRateInfo.HR_EMPTY_VALUE);
        bArr[4] = userInfo.f19671e;
        bArr[5] = userInfo.f19672f;
        bArr[6] = userInfo.f19673g;
        bArr[7] = userInfo.f19674h;
        C3910h j_ = j_();
        if (j_ == null) {
            GuliLog.m12370d(ar, "getDeviceInfo return null in setUserInfo function!!!");
            return false;
        }
        GuliLog.m12370d(ar, "device info:" + j_);
        if (j_.m25441b() || j_.m25440a() || j_.f19716f >= 16779599) {
            bArr[8] = userInfo.f19676j;
        } else {
            bArr[8] = am;
        }
        bArr[9] = (byte) (j_.f19712b & HeartRateInfo.HR_EMPTY_VALUE);
        bArr[10] = (byte) (j_.f19713c & HeartRateInfo.HR_EMPTY_VALUE);
        if (userInfo.f19675i.length <= 9) {
            i = userInfo.f19675i.length;
        }
        for (int i3 = 0; i3 < i; i3++) {
            bArr[i3 + 11] = userInfo.f19675i[i3];
        }
        byte[] bArr2 = new byte[19];
        while (i2 < 19) {
            bArr2[i2] = bArr[i2];
            i2++;
        }
        i = GattUtils.m25342d(bArr2);
        String address = m25277f().getAddress();
        bArr[19] = (byte) (i ^ Integer.decode("0x" + address.substring(address.length() - 2)).intValue());
        return write(this.aS, bArr);
    }

    public boolean m25607c(byte b) {
        return write(this.aT, new byte[]{aG, b});
    }

    public boolean m25608c(int i) {
        byte[] bArr = new byte[]{(byte) (i & HeartRateInfo.HR_EMPTY_VALUE), (byte) ((i >> 8) & HeartRateInfo.HR_EMPTY_VALUE), (byte) ((i >> 16) & HeartRateInfo.HR_EMPTY_VALUE), (byte) ((i >> 24) & HeartRateInfo.HR_EMPTY_VALUE)};
        return write(this.aT, new byte[]{ap, bArr[0], bArr[1], bArr[2], bArr[3]});
    }

    public boolean m25609c(boolean z) {
        this.br = z;
        this.bp = -1;
        if (z) {
            return write(this.bc, new byte[]{an});
        }
        return write(this.bc, new byte[]{am});
    }

    public boolean m25610d(byte b) {
        GuliLog.m12371e();
        return write(this.bb, new byte[]{av, b});
    }

    public boolean m25611d(int i) {
        GuliLog.m12371e();
        if (this.bf == null) {
            return false;
        }
        return write(this.bf, new byte[]{ap, (byte) i});
    }

    public boolean m25612d(boolean z) {
        int i = 1;
        GuliLog.m12371e();
        BluetoothGattCharacteristic bluetoothGattCharacteristic = this.aQ;
        byte[] bArr = new byte[1];
        if (!z) {
            i = 0;
        }
        bArr[0] = (byte) i;
        return write(bluetoothGattCharacteristic, bArr);
    }

    public boolean m25613e(byte b) {
        GuliLog.m12371e();
        return write(this.bb, new byte[]{ax, b});
    }

    public C3910h j_() {
        GuliLog.m12371e();
        if (this.bl != null) {
            return this.bl;
        }
        byte[] g = read(this.aP);
        GuliLog.ASSERT_NOT_NULL((Object) g);
        if (g == null || (g.length != 16 && g.length != 20)) {
            return null;
        }
        GuliLog.m12350a("device info ret len:" + g.length);
        int d = (g[3] & HeartRateInfo.HR_EMPTY_VALUE) ^ GattUtils.m25342d(new byte[]{g[0], g[1], g[2], g[3], g[4], g[5], g[6]});
        GuliLog.ASSERTION_TRUE(d == (g[7] & HeartRateInfo.HR_EMPTY_VALUE));
        if (d != (g[7] & HeartRateInfo.HR_EMPTY_VALUE)) {
            GuliLog.WARN("DeviceInfo CRC verification failed");
            return null;
        }
        String format = String.format("%02X%02X%02X%02X%02X%02X%02X%02X", new Object[]{Byte.valueOf(g[0]), Byte.valueOf(g[1]), Byte.valueOf(g[2]), Byte.valueOf(g[3]), Byte.valueOf(g[4]), Byte.valueOf(g[5]), Byte.valueOf(g[6]), Byte.valueOf(g[7])});
        int a = GattUtils.m25320a(g, 8);
        int a2 = GattUtils.m25320a(g, 12);
        if (g.length == 20) {
            this.bl = new C3910h(format, a, a2, GattUtils.m25320a(g, 16));
        } else {
            this.bl = new C3910h(format, a, a2);
        }
        return this.bl;
    }

    public int k_() {
        GuliLog.m12371e();
        byte[] g = read(this.aU);
        if (g == null) {
            GuliLog.m12370d(ar, "getRealtimeSteps return null!!!");
            return -1;
        }
        int length = g.length;
        if (length == 2) {
            return (g[0] & HeartRateInfo.HR_EMPTY_VALUE) | ((g[1] & HeartRateInfo.HR_EMPTY_VALUE) << 8);
        }
        if (length == 3) {
            return (g[0] & HeartRateInfo.HR_EMPTY_VALUE) | ((g[1] & HeartRateInfo.HR_EMPTY_VALUE) << 8);
        }
        if (length == 4) {
            return (((g[0] & HeartRateInfo.HR_EMPTY_VALUE) | ((g[1] & HeartRateInfo.HR_EMPTY_VALUE) << 8)) | ((g[2] & HeartRateInfo.HR_EMPTY_VALUE) << 16)) | ((g[3] & HeartRateInfo.HR_EMPTY_VALUE) << 24);
        }
        GuliLog.m12370d(ar, "getRealtimeSteps data length<" + length + "> error!!!");
        return -1;
    }

    @SuppressLint({"NewApi"})
//    protected boolean m25614t() {
//        GuliLog.m12371e();
//        Object a = getService(h_);
//        GuliLog.ASSERT_NOT_NULL(a);
//        if (a == null) {
//            return false;
//        }
//        this.aP = a.getCharacteristic(i_);
//        GuliLog.ASSERT_NOT_NULL(this.aP);
//        if (this.aP == null) {
//            return false;
//        }
//        GuliLog.ASSERTION_TRUE((this.aP.getProperties() & 2) > 0);
//        this.aQ = a.getCharacteristic(f);
//        GuliLog.ASSERT_NOT_NULL(this.aQ);
//        if (this.aQ == null) {
//            return false;
//        }
//        GuliLog.ASSERTION_TRUE((this.aQ.getProperties() & 2) > 0);
//        GuliLog.ASSERTION_TRUE((this.aQ.getProperties() & 8) > 0);
//        this.aR = a.getCharacteristic(j_);
//        GuliLog.ASSERT_NOT_NULL(this.aR);
//        if (this.aR == null) {
//            return false;
//        }
//        GuliLog.ASSERTION_TRUE((this.aR.getProperties() & 16) > 0);
//        this.aS = a.getCharacteristic(k_);
//        GuliLog.ASSERT_NOT_NULL(this.aS);
//        if (this.aS == null) {
//            return false;
//        }
//        GuliLog.ASSERTION_TRUE((this.aS.getProperties() & 2) > 0);
//        GuliLog.ASSERTION_TRUE((this.aS.getProperties() & 8) > 0);
//        this.aT = a.getCharacteristic(l_);
//        GuliLog.ASSERT_NOT_NULL(this.aT);
//        if (this.aT == null) {
//            return false;
//        }
//        GuliLog.ASSERTION_TRUE((this.aT.getProperties() & 8) > 0);
//        this.aU = a.getCharacteristic(m_);
//        GuliLog.ASSERT_NOT_NULL(this.aU);
//        if (this.aU == null) {
//            return false;
//        }
//        GuliLog.ASSERTION_TRUE((this.aU.getProperties() & 2) > 0);
//        GuliLog.ASSERTION_TRUE((this.aU.getProperties() & 16) > 0);
//        this.aV = a.getCharacteristic(k);
//        GuliLog.ASSERT_NOT_NULL(this.aV);
//        if (this.aV == null) {
//            return false;
//        }
//        GuliLog.ASSERTION_TRUE((this.aV.getProperties() & 16) > 0);
//        this.aW = a.getCharacteristic(l);
//        GuliLog.ASSERT_NOT_NULL(this.aW);
//        if (this.aW == null) {
//            return false;
//        }
//        GuliLog.ASSERTION_TRUE((this.aW.getProperties() & 4) > 0);
//        this.aX = a.getCharacteristic(m);
//        GuliLog.ASSERT_NOT_NULL(this.aX);
//        if (this.aX == null) {
//            return false;
//        }
//        GuliLog.ASSERTION_TRUE((this.aX.getProperties() & 2) > 0);
//        GuliLog.ASSERTION_TRUE((this.aX.getProperties() & 8) > 0);
//        this.aY = a.getCharacteristic(n);
//        GuliLog.ASSERT_NOT_NULL(this.aY);
//        if (this.aY == null) {
//            return false;
//        }
//        GuliLog.ASSERTION_TRUE((this.aY.getProperties() & 2) > 0);
//        GuliLog.ASSERTION_TRUE((this.aY.getProperties() & 8) > 0);
//        this.ba = a.getCharacteristic(p);
//        GuliLog.ASSERT_NOT_NULL(this.ba);
//        if (this.ba == null) {
//            return false;
//        }
//        GuliLog.ASSERTION_TRUE((this.ba.getProperties() & 2) > 0);
//        GuliLog.ASSERTION_TRUE((this.ba.getProperties() & 16) > 0);
//        this.bb = a.getCharacteristic(q);
//        GuliLog.ASSERT_NOT_NULL(this.bb);
//        if (this.bb == null) {
//            return false;
//        }
//        GuliLog.ASSERTION_TRUE((this.bb.getProperties() & 8) > 0);
//        boolean b = registerNotification(this.aR, new C3943k(this));
//        GuliLog.ASSERTION_TRUE(b);
//        if (!b) {
//            return false;
//        }
//        b = registerNotification(this.aU, new C3944l(this));
//        GuliLog.ASSERTION_TRUE(b);
//        if (!b) {
//            return false;
//        }
//        b = registerNotification(this.aV, null);
//        GuliLog.ASSERTION_TRUE(b);
//        if (!b) {
//            return false;
//        }
//        b = registerNotification(this.ba, new C3945m(this));
//        GuliLog.ASSERTION_TRUE(b);
//        if (!b) {
//            return false;
//        }
//        this.bc = a.getCharacteristic(r);
//        this.bd = a.getCharacteristic(s);
//        GuliLog.ASSERT_NOT_NULL(this.bd);
//        if (this.bd == null) {
//            GuliLog.m12370d(ar, "m_CharPair is null!!!");
//        }
//        BluetoothGattService a2 = getService(C3934a.f19863t);
//        if (a2 != null) {
//            this.be = a2.getCharacteristic(C3934a.f19865v);
//            registerNotification(this.be, new C3946n(this));
//            this.bf = a2.getCharacteristic(u);
//        }
//        a2 = getService(w);
//        if (a2 != null) {
//            this.bg = a2.getCharacteristic(y);
//            GuliLog.ASSERT_NOT_NULL(this.bg);
//            this.bi = a2.getCharacteristic(z);
//            GuliLog.ASSERT_NOT_NULL(this.bi);
//            this.bh = a2.getCharacteristic(x);
//            GuliLog.ASSERT_NOT_NULL(this.bh);
//            this.bj = a2.getCharacteristic(A);
//            GuliLog.ASSERT_NOT_NULL(this.bj);
//            m25561A();
//        }
//        a2 = getService(B);
//        if (a2 != null) {
//            this.bk = a2.getCharacteristic(C);
//        }
//        return true;
//    }

    public boolean m25615u() {
        return this.d_ == 3 && m25279g() == XMBLEMSTATUS.CONNECTED;
    }

    public boolean m25616v() {
        return (this.d_ == 1 || this.d_ == 3) && m25279g() == XMBLEMSTATUS.CONNECTED;
    }

    public void m25617w() {
        GuliLog.m12371e();
        if (this.aR != null) {
            unregisterNotification(this.aR);
        }
        if (this.aU != null) {
            unregisterNotification(this.aU);
        }
        if (this.aV != null) {
            unregisterNotification(this.aV);
        }
        if (this.ba != null) {
            unregisterNotification(this.ba);
        }
        this.d_ = 0;
        this.bl = null;
    }

    public C3918p m25618x() {
        GuliLog.m12371e();
        byte[] g = read(this.aX);
        if (g == null || g.length == 0) {
            return null;
        }
        GuliLog.ASSERTION_TRUE(g.length == 12);
        return new C3918p(((g[0] & HeartRateInfo.HR_EMPTY_VALUE) | ((g[1] & HeartRateInfo.HR_EMPTY_VALUE) << 8))
                & 65535, ((g[2] & HeartRateInfo.HR_EMPTY_VALUE) | ((g[3] & HeartRateInfo.HR_EMPTY_VALUE) << 8))
                & 65535, ((g[4] & HeartRateInfo.HR_EMPTY_VALUE) | ((g[5] & HeartRateInfo.HR_EMPTY_VALUE) << 8))
                & 65535, ((g[6] & HeartRateInfo.HR_EMPTY_VALUE) | ((g[7] & HeartRateInfo.HR_EMPTY_VALUE) << 8))
                & 65535, ((g[8] & HeartRateInfo.HR_EMPTY_VALUE) | ((g[9] & HeartRateInfo.HR_EMPTY_VALUE) << 8))
                & 65535, ((g[10] & HeartRateInfo.HR_EMPTY_VALUE) | ((g[11] & HeartRateInfo.HR_EMPTY_VALUE) << 8))
                & 65535);
    }

    public int m25619y() {
        return this.d_;
    }

    public void m25620z() {
        m25564D();
    }
}

